$import("com.joypard.platform.account.user.UserView");

/**
 * 用户
 */
K.defCtrl("com.joypard.platform.account.user.UserCtrl", {
	view : null,
	initialize : function() {
		this.view = UserView.instance({
			userCtrl : this
		});

		E.addListener("updateUserEvent", this.onUpdateUser, this);
		E.addListener("addUserEvent", this.onAddUser, this);
		E.addListener("delUserEvent", this.onDelUser, this);

		E.addEvents("updateUserSuccessEvent");
		E.addEvents("addUserSuccessEvent");
		E.addEvents("delUserSuccessEvent");
	},

	/**
	 * 更新用户信息
	 */
	onUpdateUser : function(form) {
		var input = K.input({
			form : form,
			success : function(text) {
				var output = K.output(text);
				if (!output.showError()) {
					E.fireEvent("updateUserSuccessEvent", output);
				}
			}
		});
		K.service(UserDI.urls.updateUser, input);
	},

	/**
	 * 新增用户信息
	 */
	onAddUser : function(form) {
		var input = K.input({
			form : form,
			success : function(text) {
				var output = K.output(text);
				if (!output.showError()) {
					E.fireEvent("addUserSuccessEvent", output);
				}
			}
		});
		K.service(UserDI.urls.addUser, input);
	},
	/**
	 * 删除用户信息
	 */
	onDelUser : function(records) {
		var input = K.input({
			params : {
				userIds : K.arrayToStr(records, "id")
			},
			success : function(text) {
				var output = K.output(text);
				if (!output.showError()) {
					E.fireEvent("delUserSuccessEvent", output);
				}
			}
		});
		K.service(UserDI.urls.delUser, input);
	}
});
